<%--
  Created by IntelliJ IDEA.
  User: c
  Date: 2024/6/6
  Time: 10:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加</title>
</head>
<body>
<h1>创建存储空间</h1>
<form method="post" action="createStorageHandler">
    <label for="storageName">存储空间名称:</label>
    <input type="text" id="storageName" name="storageName" placeholder="请输入存储空间名称" required maxlength="63">
    <br>

    <label>存储类型:</label>
    <input type="radio" name="type" id="standard" value="标准存储" checked>标准存储
    <input type="radio" name="type" id="lowAccess" value="低频访问存储">低频访问存储
    <input type="radio" name="type" id="archive" value="归档存储">归档存储
    <br>

    <label>读写权限:</label>
    <input type="radio" name="permission" id="private" value="Pri" checked>私有（Pri）
    <input type="radio" name="permission" id="publicR" value="R">公共读（R）
    <input type="radio" name="permission" id="publicRW" value="RW">公共读写（RW）
    <br>

    <button type="submit" id="sure">确定</button>
    <button type="reset" id="cancle">取消</button>
</form>
</body>
</html>
<script>
    function verifyName() {
        let bucketName = $('#bucketName').val();
        let flowName = false;
        $.ajax({
            url: "oss/oss.action",
            type: 'get',
            data: {opr: 'selectName', bucketName},
            dataType: 'json',
            success: function (data) {
                if (data == null) {
                    let opr = "add";
                    let bucketName = $('#bucketName').val().trim()
                    if(bucketName.length===0){
                        alert("请填写储存空间名称！")
                        return;
                    }
                    let type = $('input[name="type"]:checked').val()
                    let permission = $('input[name="permission"]:checked').val()
                    let params = {opr, bucketName, type, permission}
                    $.ajax({
                        url: "oss/oss.action",
                        type: 'post',
                        data: params,
                        dataType: 'json',
                        success: function (data) {
                            console.log(data);
                            if (data.code == 'ok') {
                                window.location.href = "ossList.jsp";
                            }
                        },
                        error: function () {
                            alert("新增失败!");
                        }
                    })
                }else {
                    alert("存储空间名称已存在！，请重新输入！")
                }
            }
        })
        return flowName;
    }
    $('#sure').click(function () {
        verifyName();
    })


    $('#cancle').click(function () {
        window.location.href = "ossList.jsp";
    })
</script>